import java.util.*;
public class Demo18{

    public static void divide(int t){

        for(int i = 2; i <= t / i; i++){
            int s = 0;
            if(t % i == 0){

                while(t % i == 0){
                    s++;
                    t /= i;
                }
                System.out.println(i + " " + s);
            }
        }
        if(t > 1)System.out.println(t+" 1");
    }
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        for(int i = 0; i < n; i++){
            int t = scan.nextInt();
            divide(t);

            System.out.println();
        }
    }
}